<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const arr = [100, 60, 80]
    /*
    console.log(arr[0]) //最大值
    console.log(arr[1]) //最小值
    console.log(arr[2]) //平均值
    const max = arr[0] //最大值
    const min = arr[1] //最小值
    const avg = arr[2] //平均值
    */

    /* 
    数组解构
      数组解构是将数组的单元值(数组元素)快速批量赋值给一系列变量的简洁语法
    基本语法
      赋值运算符=左则的[]用于批量声明变量，右则数组的单元值(数组元素)将被赋值给左则的变量
      变量的顺序对应数组单元值的位置依次进行赋值操作
    */

    const [max, min, avg] = [100, 60, 80]
    /*
    类似于：
        const max = arr[0] //最大值
        const min = arr[1] //最小值
        const avg = arr[2] //平均值
    */
    console.log(max, min, avg);//100，60，80

    console.log("--------------------------");

    const pc = ["海尔", "联想", "小米", "方正"]
    const [hr, lx, mi, fz] = pc
    console.log(hr, lx, mi, fz);

    console.log("--------------------------");

    function getValue() {
      return [1000, 600]
    }
    const [maxNum, minNum] = getValue()
    console.log(maxNum, minNum);

    console.log("--------------------------");

    // 剩余参数
    const [a, b, ...args] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    console.log(a, b, args);// 1 2 [4,5,6,7,8,9,10]

    console.log("--------------------------");

    //默认值
    let [num1 = 0, num2 = 0] = [18, 38]
    console.log(num1, num2);

    console.log("--------------------------");

    // 解构的同时忽略数组某一个元素
    const [q, , w] = [1, 2, 3]
    console.log(q, w);

    console.log("--------------------------");

    //多维数组
    const array = [1, 2, [3, 4]]
    console.log(array[0]);
    console.log(array[1]);
    console.log(array[2][0]);

    console.log("--------------------------");

    //多维数组解构
    const array2 = [1, 2, [3, 4]]
    const [value1, value2, [children1,children2]] = array2
    console.log(value1, value2, children1,children2);


  </script>
</body>

</html>